package com.wolfman.wolfchat.config;

import com.wolfman.wolfchat.component.WebSocketServer;
import com.wolfman.wolfchat.service.MessageService;
import com.wolfman.wolfchat.service.UserService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

import javax.annotation.Resource;

/**
 * @Title
 * @Description
 * @Author WolfMan
 * @Date 2022/1/15 0:41
 * @Email 2370032534@qq.com
 */
@Configuration
public class WebSocketConfig {

    @Resource
    UserService userService;

    @Resource
    MessageService messageService;

    /**
     * 注入一个ServerEndpointExporter,该Bean会自动注册使用@ServerEndpoint注解申明的websocket endpoint
     */
    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }

    @Bean
    public void setBeanList() {
        WebSocketServer.userService = userService;
        WebSocketServer.messageService = messageService;
    }
}
